# python+selenium自动化演示代码

# 第一种UI自动化通过ID定位控件
# from selenium import webdriver
# # 先导入webdriver
# driver = webdriver.firefox()
# # 相当于对模块中的类进行实例化，这段代码会打开浏览器
# driver.get('http://101.133.169.100/yuns/index.php')
# # 打开XXX网页
# driver.find_element_by_id('cart_num').click()
# # 通过ID去定位控件，click可以实现对控件的点击

# 第二种UI自动化通过name定位控件
# from selenium import webdriver
# # 先导入webdriver
# driver = webdriver.Chrome()
# # 相当于对模块中的类进行实例化，这段代码会打开浏览器
# driver.get('http://101.133.169.100/yuns/index.php')
# # 打开XXX网页
# driver.find_element_by_name('key').send_keys('XXX')
# 通过name去定位控件，send_keys可以对输入框进行输入

# # 第三种UI自动化通过class name定位控件
# from selenium import webdriver
# # 先导入webdriver
# driver = webdriver.Chrome()
# # 相当于对模块中的类进行实例化，这段代码会打开浏览器
# driver.get('http://101.133.169.100/yuns/index.php')
# # 打开XXX网页
# driver.find_element_by_class_name('but2').click()
# 通过class name去定位控件,再进行点击

# 特殊情况需要注意复合类，比如中间有空格，不建议用class name进行定位

# 以上三种定位方式选择其中的一种定位即可
#
# 跑一个购物场景练习
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/goods/27.html')
# time.sleep(10)
# # driver.find_element_by_partial_link_text('小个子棉衣矮韩版2017').click()
# # time.sleep(10)
# driver.find_element_by_xpath("//a[@title='白']").click()
# time.sleep(10)
# driver.find_element_by_xpath("//a[@title='M']").click()
# time.sleep(10)
# driver.find_element_by_id('num_plus').click()
# time.sleep(10)
# driver.find_element_by_partial_link_text('购买').click()

# # 第一种UI自动化通过ID定位控件_练习1
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.find_element_by_id('cart_num').click()

# 第一种UI自动化通过ID定位控件_练习2
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/goods/27.html')
# time.sleep(10)
# driver.find_element_by_id('num_plus').click()

# # 第一种UI自动化通过ID定位控件_练习3
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login?returnUrl=http%3A%2F%2F101.133.169.100%2Fyuns%2Findex.php%2Fgoods%3Fkey%3DT%25E6%2581%25A4%25E7%2594%25B72016')
# time.sleep(10)
# driver.find_element_by_id('text').send_keys('18888888888')
# # 第一种UI自动化通过ID定位控件_练习4
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/buy/index')
# time.sleep(10)
# driver.find_element_by_name('username').send_keys('18888888888')
# time.sleep(5)
# driver.find_element_by_name('password').send_keys('123456')
# time.sleep(5)
# driver.find_element_by_class_name('submit_login').click()
# time.sleep(5)
# driver.find_element_by_link_text('会员中心').click()
# time.sleep(10)
# driver.find_element_by_link_text('账户设置').click()
# time.sleep(5)
# driver.find_element_by_id('nick').send_keys('888')

# # 第一种UI自动化通过ID定位控件_练习5
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('https://www.baidu.com/')
# driver.find_element_by_id('kw').send_keys('yh定位测试')
# 第二种UI自动化通过name定位控件_练习1
# from selenium import webdriver
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# driver.find_element_by_name('key').send_keys('XXX')

# 第二种UI自动化通过name定位控件_练习2
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login?returnUrl=http%3A%2F%2F101.133.169.100%2Fyuns%2Findex.php%2Fgoods%3Fkey%3DT%25E6%2581%25A4%25E7%2594%25B72016')
# time.sleep(10)
# driver.find_element_by_name('username').send_keys('18888888888')

# 第二种UI自动化通过name定位控件_练习3
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/buy/index')
# time.sleep(10)
# driver.find_element_by_name('username').send_keys('18888888888')
# time.sleep(5)
# driver.find_element_by_name('password').send_keys('123456')
# time.sleep(5)
# driver.find_element_by_class_name('submit_login').click()
# time.sleep(5)
# driver.find_element_by_link_text('会员中心').click()
# time.sleep(10)
# driver.find_element_by_name('keyword').send_keys('11111')

# 第二种UI自动化通过name定位控件_练习4
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/buy/index')
# time.sleep(10)
# driver.find_element_by_name('username').send_keys('18888888888')
# time.sleep(5)
# driver.find_element_by_name('password').send_keys('123456')
# time.sleep(5)
# driver.find_element_by_class_name('submit_login').click()
# time.sleep(5)
# driver.find_element_by_link_text('会员中心').click()
# time.sleep(10)
# driver.find_element_by_link_text('账户设置').click()
# time.sleep(5)
# driver.find_element_by_name('nick').send_keys('999')

# 第二种UI自动化通过name定位控件_练习5
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/buy/index')
# time.sleep(10)
# driver.find_element_by_name('username').send_keys('18888888888')
# time.sleep(5)
# driver.find_element_by_name('password').send_keys('123456')
# time.sleep(5)
# driver.find_element_by_class_name('submit_login').click()
# time.sleep(5)
# driver.find_element_by_link_text('会员中心').click()
# time.sleep(10)
# driver.find_element_by_link_text('账户设置').click()
# time.sleep(5)
# driver.find_element_by_id('nick').send_keys('999')
# time.sleep(5)
# driver.find_element_by_name('address').send_keys('陕西省')

# # 第三种UI自动化通过class name定位控件_练习1
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.find_element_by_class_name('but2').click()

# # 第三种UI自动化通过class name定位控件_练习2
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/goods/37.html')
# time.sleep(10)
# driver.find_element_by_class_name('collect_goods').click()



# # 第三种UI自动化通过class name定位控件_练习3
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login?returnUrl=http%3A%2F%2F101.133.169.100%2Fyuns%2Findex.php%2Fgoods%3Fkey%3DT%25E6%2581%25A4%25E7%2594%25B72016')
# time.sleep(10)
# driver.find_element_by_name('username').send_keys('18888888888')
# time.sleep(5)
# driver.find_element_by_name('password').send_keys('123456')
# time.sleep(5)
# driver.find_element_by_class_name('submit_login').click()

# # 第三种UI自动化通过class name定位控件_练习4
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login?returnUrl=http%3A%2F%2F101.133.169.100%2Fyuns%2Findex.php%2Fgoods%3Fkey%3DT%25E6%2581%25A4%25E7%2594%25B72016')
# time.sleep(10)
# driver.find_element_by_class_name('lunbo').click()

# # 第三种UI自动化通过class name定位控件_练习5
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/goods/27.html')
# time.sleep(10)
# driver.find_element_by_class_name('coupon_receive').click()

# 通过link_text定位练习1
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get("http://101.133.169.100/yuns/index.php")
# time.sleep(5)
# driver.find_element_by_link_text('秒杀').click()
# 通过link_text定位练习2
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get("http://101.133.169.100/yuns/index.php")
# time.sleep(5)
# driver.find_element_by_link_text('夏天最热').click()
# 通过link_text定位练习3
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get("http://101.133.169.100/yuns/index.php")
# time.sleep(5)
# driver.find_element_by_link_text('运动男鞋').click()

# 通过partial_link_text定位控件_练习1
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.find_element_by_partial_link_text('阿里脱贫基金').click()
# 通过partial_link_text定位控件_练习2
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_partial_link_text('上的所有故事').click()
# 通过partial_link_text定位控件_练习3
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_partial_link_text('质长绒棉A字型条纹连衣').click()

# 通过xpath绝对路径定位控件_练习1
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.maximize_window()
# driver.execute_script("window.scrollTo(0,document.body.scrollHeight*0.5)")
# driver.find_element_by_xpath("/html/body/div/div/div/div[@class='con']/div[@class='c']/dl/dd/a[@href='http://101.133.169.100/yuns/index.php/goods/35.html']").click()
# # 通过xpath绝对路径定位控件_练习2
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.execute_script("window.scrollTo(0,document.body.scrollHeight*1)")#滚动条拖动到最下边
# driver.find_element_by_xpath('/html/body/div/div/div/div/dl/dd/a[@href="http://101.133.169.100/yuns/index.php/news/help/id/9.html"]').click()
# 通过xpath绝对路径定位控件_练习3
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_xpath("/html/body/div/div/div/a[text()='登录']").click()

# 通过xpath相对路径定位_练习1_根据自身特有属性定位自身
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.maximize_window()
# driver.find_element_by_xpath("//a[text()='登录']").click()
# 通过xpath相对路径定位_练习2_根据自身特有属性定位自身
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.maximize_window()
# driver.find_element_by_xpath("//a[text()='女装' and @href='http://101.133.169.100/yuns/index.php/goods?key=女装']").click()
# # 通过xpath相对路径定位_练习3_根据自身特有属性定位自身
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(2)
# driver.execute_script("window.scrollTo(0,document.body.scrollHeight*0.25)")
# time.sleep(2)
# driver.find_element_by_xpath("//a[text()='品牌专卖']").click()
# 通过xpath相对路径定位_练习4_根据自身特有属性定位自身
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.maximize_window()
# driver.find_elements_by_xpath("//a[text()='女装']")[0].click()
# 通过xpath相对路径定位_练习5_根据自身特有属性定位自身
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.maximize_window()
# driver.find_element_by_xpath("//a[text()='注册']").click()
# 通过xpath相对路径定位_练习6_根据父级特有属性定位自身
# from selenium import webdriver
# from time import sleep
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# sleep(5)
# driver.maximize_window()
# sleep(2)
# driver.find_element_by_xpath("//div[@class='schhot']/a[text()='9.9抢大牌']").click()
# 通过xpath相对路径定位_练习7_根据父级特有属性定位自身
# from selenium import webdriver
# from time import sleep
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# sleep(5)
# driver.maximize_window()
# sleep(2)
# driver.find_element_by_xpath("//div[@class='small_cart_name']/span").click()
# 通过xpath相对路径定位_练习8_根据父级特有属性定位自身
# from selenium import webdriver
# from time import sleep
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# sleep(5)
# driver.maximize_window()
# sleep(2)
# driver.find_element_by_xpath("//div[@class='con1']/a[text()='“天路”上的所有故事，都...']").click()
# 通过xpath相对路径定位_练习9_根据父级特有属性定位自身
# from selenium import webdriver
# from time import sleep
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# sleep(5)
# driver.maximize_window()
# sleep(2)
# driver.find_element_by_xpath("//div[@class='schbox']/form/input[@class='but1']").send_keys('短袖')
# sleep(3)
# driver.find_element_by_xpath("//div[@class='schbox']/form/input[@type='submit']").click()
# 通过xpath相对路径定位_练习10_根据父级特有属性定位自身
# from selenium.webdriver.common.action_chains import ActionChains#从XXX中使用ActionChains定格方法
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/goods/37.html')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(2)
# dg = driver.find_element_by_xpath("//div[@class='wapbuycode']/a")#通过xpath定位到某一控件
# time.sleep(3)
# ActionChains(driver).move_to_element(dg).perform()#移动到该控件并且定格到该处，perform意思是让该条命令生效
# 通过xpath相对路径定位_练习11_根据自身特有属性定位父级
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_xpath("//a[text()='家电数码']/../../../..").click()
# 通过xpath相对路径定位_练习12_根据自身特有属性定位父级
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_xpath("//a[text()='首页']/..//a[text()='我的订单']").click()
# 通过xpath相对路径定位_练习13_根据自身特有属性定位父级
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_xpath("//a[text()='运动男鞋']/..").click()
# 通过xpath相对路径定位_练习14_根据自身特有属性定位父级
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.execute_script("window.scrollTo(0,document.body.scrollHeight*1)")
# driver.find_element_by_xpath("//a[text()='UQ云商系统']/..")
# 通过xpath相对路径定位_练习15_根据自身特有属性定位父级
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.execute_script("window.scrollTo(0,document.body.scrollHeight*1)")
# driver.find_element_by_xpath("//a[text()='价格保护']/../..")

# 通过css绝对路径定位练习1
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.find_element_by_css_selector('html>body>div>div>div>div>a:nth-child(2)').click()
# 通过css绝对路径定位练习2
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.find_element_by_css_selector('html>body>div>div>div>div>a:nth-child(2)').click()
# 通过css绝对路径定位练习3
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.find_element_by_css_selector('html>body>div>div>div.seckill>div.con>div.skbox:nth-child(1)>div.ttl>a').click()

# 通过css相对路径定位练习1
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# driver.find_element_by_css_selector('div.skbox:first-child>div.ttl>a').click()
# 通过css相对路径定位练习2
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_css_selector('div.small_cart_name>span').click()
# 通过css相对路径定位练习3
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_css_selector('i#cart_num').click()
# 通过css相对路径定位练习4
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_css_selector('div.con>p>a:first-child').click()
# 通过css相对路径定位练习5
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_css_selector('div.reg_name>a').click()
# 通过css相对路径定位练习6
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/register')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_css_selector('a.connect:first-child>span').click()
# 通过css相对路径定位练习7
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_css_selector('div.con>p>a:first-child').click()
# time.sleep(5)
# driver.find_element_by_css_selector('input#text').send_keys('18888888888')
# time.sleep(2)
# driver.find_element_by_css_selector('input#password').send_keys('123456')
# time.sleep(2)
# driver.find_element_by_css_selector('input.submit_login').click()
# 通过css相对路径定位练习8
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_css_selector('div.con>p>a:first-child').click()
# time.sleep(5)
# driver.find_element_by_css_selector('input#text').send_keys('18888888888')
# time.sleep(2)
# driver.find_element_by_css_selector('input#password').send_keys('123456')
# time.sleep(2)
# driver.find_element_by_css_selector('input.submit_login').click()
# time.sleep(5)
# driver.find_element_by_css_selector('div.con>p>a:nth-child(1)').click()
# 通过css相对路径定位练习9
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(5)
# driver.find_element_by_css_selector('div.con>p>a:first-child').click()
# time.sleep(5)
# driver.find_element_by_css_selector('input#text').send_keys('18888888888')
# time.sleep(2)
# driver.find_element_by_css_selector('input#password').send_keys('123456')
# time.sleep(2)
# driver.find_element_by_css_selector('input.submit_login').click()
# time.sleep(5)
# driver.find_element_by_css_selector('div.con>p>a:nth-child(1)').click()
# time.sleep(5)
# driver.find_element_by_css_selector('div.smore>a:nth-child(2)').click()
# 通过css相对路径定位练习10
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('https://www.baidu.com/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(2)
# driver.find_element_by_css_selector('input.s_ipt').send_keys('编测编学')
# time.sleep(2)
# driver.find_element_by_css_selector('input#su').click()
# 通过css相对路径定位练习11
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/goods?cid=&brand=&attr=')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(2)
# driver.find_element_by_css_selector('dl.pp>dd>a:nth-child(3)').click()
# 通过css相对路径定位练习12
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/goods?cid=&brand=&attr=')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(2)
# driver.execute_script("window.scrollTo(0,document.body.scrollHeight*1)")
# time.sleep(2)
# driver.find_element_by_css_selector('div.contact_help>dl:nth-child(4)>dd:nth-child(3)>a').click()
# 通过css相对路径定位练习13
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/news/help/id/24.html')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(2)
# driver.find_element_by_css_selector('div.lmenu>dl:nth-child(2)>dt>span').click()
# 通过css相对路径定位练习14
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(2)
# driver.find_element_by_css_selector('dl.type:nth-child(6)>dt>div.mbig>span>a').click()
# 通过css相对路径定位练习15
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# time.sleep(5)
# driver.maximize_window()
# time.sleep(2)
# driver.find_element_by_css_selector('div.logo>div.img>a>img').click()

# 跑一个简单的购物场景
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('http://101.133.169.100/yuns/index.php/buy/index')
time.sleep(10)
driver.find_element_by_name('username').send_keys('18888888888')
time.sleep(5)
driver.find_element_by_name('password').send_keys('123456')
time.sleep(5)
driver.find_element_by_class_name('submit_login').click()
time.sleep(5)
driver.maximize_window()
time.sleep(2)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight*0.25)")
time.sleep(5)
driver.find_element_by_link_text('小个子棉衣矮韩版2017新款百搭冬装袄羽绒棉服潮').click()
time.sleep(10)
print(driver.current_window_handle)
driver.switch_to.window(driver.window_handles[1])
time.sleep(5)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight*0.1)")
time.sleep(10)
driver.find_element_by_xpath("//a[@title='白']").click()
time.sleep(10)
driver.find_element_by_xpath("//a[@title='M']").click()
time.sleep(10)
driver.find_element_by_css_selector('a.yyue.nowbuy>i').click()
time.sleep(10)
driver.find_element_by_xpath("//a[text()='继续购物']").click()
# 以上场景报错总结：
# 总是报错定位不到控件，经过分析有以下两点：
# 1.等待时间不够，控件未加载完成
# 2.跳到新窗体时，未设置窗体句柄到第二个窗体，所以新窗体控件无法定位
# 以上错误，需格外注意！